import ctypes
import os
import sys

from PyQt5 import QtWidgets
from PyQt5.QtCore import QPoint
from PyQt5.QtGui import QMouseEvent

from Ui.Scan import Ui_MainWindow
from Init.InitParrten import *
from Service.BtnFunction import BtnFunction
from Utils.ChangeMac import is_admin


class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, BtnFunction):
    def __init__(self):
        super(MainWindow, self).__init__()
        super(BtnFunction, self).__init__()
        self.setupUi(self)
        setWindowFlag(self)
        setInputMask(self)
        setTimerConnection(self)
        setBtnConnection(self)
        catchTerminal(self)
        getCurrentIp(self)
        setParrten(self)
        connectDatabase(self)





    def mouseMoveEvent(self, e: QMouseEvent):
        if self._tracking:
            self._endPos = e.pos() - self._startPos
            self.move(self.pos() + self._endPos)

    def mousePressEvent(self, e: QMouseEvent):
        if e.button() == Qt.LeftButton:
            self._startPos = QPoint(e.x(), e.y())
            self._tracking = True

    def closeEvent(self, event):
        self.connect.close()
        os.system("taskkill /f /im GacaNetWork.exe")


if __name__ == "__main__":
    if is_admin():
        app = QtWidgets.QApplication(sys.argv)
        Ui = MainWindow()
        Ui.show()
        sys.exit(app.exec_())
    else:
        if sys.version_info[0] == 3:
            ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)
